package blyth;

/*
 * Knowledge
 * The information that is presently available from the
 * agents about the world.
 */
public class Knowledge {    
    
    private World world;
    public static int myTeamTimeLeft = 180;

    public Knowledge() {
        world = new World();
    }

    public Command Act(Beliefs beliefs) {
        myTeamTimeLeft = beliefs.teamTimeLeft;
        Agent myAgent = new Agent(beliefs.id, beliefs.team, beliefs.energy,
                beliefs.pos, beliefs.dir);
        myAgent.inWater = beliefs.inWater;
        myAgent = Monitoring(beliefs, myAgent);        
        return myAgent.GetTask().Solve();
    }

    private Agent Monitoring(Beliefs beliefs, Agent myAgent) {
        // Setting my team's ID (set once)
        world.MyTeamID(beliefs.team);
        
        // Manage info from seen agents
        for (int i = 0; i < beliefs.agents.size(); i++) {
            world.ManageHostileAgent(beliefs.agents.get(i));
        }

        // Manage info from my agent
        myAgent = world.ManageFriendlyAgent(myAgent);        

        // Manage info from seen foods
        world.ManageFood(myAgent, beliefs.foods);

        // Validate existing tasks
        world.ValidateTasks();
        
        // Make new tasks
        world.MakeNewTasks();
        
        // Check for rotation conditions
        world.ManageRotation();

        return myAgent;
    }
    
    @Override
    public String toString() {
        return world.toString();
    }
}
